package com.example.design.c.observer.demo2;

import cn.hutool.core.collection.CollUtil;

import java.util.List;

/**
 * 观察者模式
 * 具体目标
 */
public class RingSubject {
    /**
     * 观察者们
     */
    private final List<RingBellEvent> events = CollUtil.list(false);

    public void add(RingBellEvent event) {
        events.add(event);
    }

    public void remove(RingBellEvent event) {
        events.remove(event);
    }

    public void notifyResponse(boolean flag) {
        for (RingBellEvent event : events) {
            event.response(flag);
        }
    }
}
